import pymysql

def create_table_unit_chat():
    unit_chat = '''
      create table if not exists unit_chat(
          id bigint(8) not null AUTO_INCREMENT,
          return_json text(65535) not null,
          primary key (id) 
      )
    '''
    #连接数据库
    connection = pymysql.connect(host='127.0.0.1', port=3306, user='root', password='123456', db='unit',
                                 charset='utf8', cursorclass=pymysql.cursors.DictCursor)
    cursor = connection.cursor()
    #查询表pv是否已经存在
    check="show tables like 'unit_chat'"
    if cursor.execute(check) == 1:
        print("表Pv已存在")
    else:
        #创建表pv
        try:
            cursor.execute(unit_chat)
            connection.commit()
            print('表unit_chat创建成功')
        except:
            print('表unit_chat创建失败')
            connection.rollback()

create_table_unit_chat()